home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / WINMODE.ARJ / WINMODE.C < prev    next >
C/C++ Source or Header  |  1992-05-19  |  4KB  |  93 lines

  1. /*+--------------------------------------------------------+
  2.   | WINMODE V1.0 FOR WINDOWS 3.1                           |
  3.   | Copyright (c) 1988-92 Finnegan O'Malley & Company Inc. |
  4.   | All Rights Reserved                                    |
  5.   | First Published in PC Magazine, May 12, 1992 [p.345]   |
  6.   |                                                        |
  7.   | Developed under Microsoft C 5.1                        |
  8.   +--------------------------------------------------------+
  9. */
  10.  
  11. /* -----------------------------------------------------
  12.    Altered/tested/debugged using Turbo C v2.0 by
  13.    Andy K.  Have not done extensive tests...if you find
  14.    bugs I'd appreciate knowing about it.  Thanks!!
  15.    Use with a command-line parameter to get the
  16.    copyright/info notice (ie  WINMODE X ).
  17.    -----------------------------------------------------
  18. */
  19.  
  20. #include <dos.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23.  
  24. #define INT_MULTIPLEX 0x2F
  25.  
  26. /*  return codes ("errorlevel") available to a .BAT file */
  27. #define MODE_DOS       0      /* running DOS                             */
  28. #define MODE_DOS_TS    1      /* running DOS Task Switcher               */
  29. #define MODE_WIN3X_STD 2      /* running WIN ver 3x Standard mode        */
  30. #define MODE_WIN3X_2X  3      /* running WIN 386 ver 2x                  */
  31. #define MODE_WINX_386E 4      /* running WIN virtual86 mode on 386/486   */
  32.  
  33. main(argc, argv)
  34.     int argc;
  35.     char *argv[];
  36. {
  37.     auto struct SREGS Seg;    /*  segment registers  */
  38.     static union REGS Reg;    /*  general registers  */
  39.  
  40.     if(argc != 1)
  41.        printf("%s 1.0 for Windows 3.1\n"
  42.               "Copyright (c) 1988-92 Finnegan O'Malley"
  43.               " & Company Inc.  All Rights Reserved.\n"
  44.               "First Published in PC Magazine,"
  45.               " May 12, 1992.\n\n",argv[0]);
  46.     segread(&Seg);            /*  initialize the segment registers  */
  47.  
  48.     Reg.x.ax = 0x1600;  /* in 386 enhanced mode?  */
  49.     int86x(INT_MULTIPLEX, &Reg, &Reg, &Seg);
  50.     switch (Reg.h.al)
  51.     {
  52.         case 0x00:  /* not in 386 Enhanced mode  */
  53.         case 0x80:  /* not in 386 Enhanced mode  */
  54.            break;
  55.         case 0x01:  /* Windows/386 2.xx is running  */
  56.         case 0xFF:  /* Windows/386 2.xx is running  */
  57.            printf("Windows/386 2.xx is running (%d)\n",
  58.               MODE_WIN3X_2X );
  59.            exit(MODE_WIN3X_2X - '0');
  60.         default:              /* in 386 Enhanced mode, where:
  61.                                  AL = major version (3., 4., ...)
  62.                                  AH = minor version (00, 10, ...)  */
  63.            printf("Windows %d.%02d is running in 386 Enhanced"
  64.                   " mode (%d)\n",Reg.h.al, Reg.h.ah,
  65.                   MODE_WINX_386E);
  66.            exit(MODE_WINX_386E - '0');
  67.     }
  68.  
  69.     Reg.x.ax = 0x4680;  /* in plain vanilla DOS mode? */
  70.     int86x(INT_MULTIPLEX, &Reg, &Reg, &Seg);
  71.     if(Reg.h.al == 0x80){     /* not in DOS Task Switcher,
  72.                                  Real or Standard mode  */
  73.        printf("Windows is not running, nor is the DOS"
  74.               " Task Switcher (%d)\n",
  75.               MODE_DOS);
  76.        exit(MODE_DOS - '0');
  77.     }
  78.  
  79.     if(getenv("windir")       /* in Real or Standard mode? */
  80.     || getenv("WINDIR")) {    /* in case it goes upper case  */
  81.  
  82.        printf("Windows 3.xx is running in Real or Standard"
  83.           " mode (%d)\n",
  84.               MODE_WIN3X_STD);
  85.        exit(MODE_WIN3X_STD - '0');
  86.     }
  87.     /*  Otherwise, the DOS MS-DOS Shell is running  */
  88.     printf("The DOS Task Switcher is running (%d)\n",
  89.             MODE_DOS_TS);
  90.     exit(MODE_DOS_TS - '0');
  91. }
  92.  
  93.